export default {
    //房间列表
    getshedatalist({ state }, obj) {
        $.hsf.startLoading()
        $.hsf.ajaxPost('room/searchRooms', obj, '', function(result) {
            if (result.code == '200') {
                $.hsf.stopLoading()
                state.shedatalist = result.data;
                for (var i = 0; i < result.data.length; i++) {
                    state.shedatalist[i].thumbUrl = $.hsf.baseUrl + result.data[i].thumbUrl
                }
            }
        })
    },
    //房间详情查询
    getsearchRoom({ state }, roomid) {
        $.hsf.startLoading()

        var obj = JSON.stringify({ roomId: roomid })
        $.hsf.ajaxPost('room/searchRoom', obj, '', function(result) {
            if (result.code == '200') {
                $.hsf.stopLoading()
                state.roomdata = result.data;
                state.swiperlists = result.data.images;
                state.facils = result.data.facilities.splice(0, 3);
                state.facilities = result.data.facilities;
            }
        })

    },
    //查询订单详情
    getorderInfos({ state }, obj) {
        $.hsf.startLoading()
        $.hsf.ajaxPost('wx/order/' + obj, '', '', function(result) {
            if (result.code == '200') {
                $.hsf.stopLoading()
                state.orderD = result.data;
                var checkinT = new Date(result.data.checkinTime);
                var checkinO = new Date(result.data.checkoutTime);
                var nDays = Math.abs(parseInt((checkinO - checkinT) / 1000 / 3600 / 24));
                state.Duration = nDays;
                var orderlist = result.data.orderAmounts;
                state.orderD.checkinTime = checkinT.getFullYear() + '年' + (checkinT.getMonth() + 1) + '月' + checkinT.getDate() + '日';
                state.orderD.checkoutTime = checkinO.getFullYear() + '年' + (checkinO.getMonth() + 1) + '月' + checkinO.getDate() + '日';
                state.orderD.thumbUrl = $.hsf.baseUrl + result.data.thumbUrl
            } else {
                $.hsf.stopLoading()
            }

        })
    },
    //查询订单列表
    getorderInfoList({ state }, obj) {
        $.hsf.ajaxPost('wx/' + $.local_Storage.getItem('wxopenid') + '/order/list', obj, '', function(result) {
            if (result.code == '200') {
                state.orderLists = result.data;
                for (var i = 0; i < result.data.length; i++) {
                    var checkinT = new Date(result.data[i].checkinTime);
                    var checkinO = new Date(result.data[i].checkoutTime);
                    state.orderLists[i].checkinTime = checkinT.getFullYear() + '年' + (checkinT.getMonth() + 1) + '月' + checkinT.getDate() + '日';
                    state.orderLists[i].checkoutTime = checkinO.getFullYear() + '年' + (checkinO.getMonth() + 1) + '月' + checkinO.getDate() + '日';
                    state.orderLists[i].thumbUrl = $.hsf.baseUrl + result.data[i].thumbUrl
                }
            }
        })
    },
    //房态查询
    roomStatus({ state }, obj) {
        $.hsf.startLoading()
        var objs = JSON.stringify(obj)
        $.hsf.ajaxPost('room/' + obj + '/0/status', objs, '', function(result) {
            if (result.code == '200') {
                $.hsf.stopLoading()
                state.dateStatus = result.data;
            }
        })
    },
    //获取会话记录
    getSession({ state }, objs) {
        console.log(objs)
        $.hsf.ajaxPost('msg/pageQueryMsgSession', objs, '', function(result) {
            if (result.code == '200') {
                state.Sessions = result.data.rows
            }
        })
    },

    //管家端房间列表
    gethostdatalist({ state }, requestData) {
        if (!requestData) {
            requestData = '';
        }
        var obj = JSON.stringify(requestData)
        $.hsf.startLoading()
        let wxopenid = $.local_Storage.getItem('wxopenid');
        if (state.serveStatus == '0') {
            // wxopenid = '123456';
        }
        $.hsf.ajaxPost('wx/mgr/' + wxopenid + '/room/searchRooms', obj, '', function(result) {
            console.log(result);
            if (result.code == '200') {
                $.hsf.stopLoading()
                state.hostdatalist = result.data;
            } else {
                $.hsf.stopLoading()
            }
        })
    },

    //管家端查询订单列表
    getHostOrderInfoList({ state }, requestData) {
        if (!requestData) {
            requestData = '';
        }
        var obj = JSON.stringify(requestData)
        $.hsf.startLoading();
        let wxopenid = $.local_Storage.getItem('wxopenid');
        if (state.serveStatus == '0') {
            // wxopenid = '123456';
        }
        $.hsf.ajaxPost('wx/mgr/' + wxopenid + '/order/list', obj, '', function(result) {
            if (result.code == '200') {
                $.hsf.stopLoading()
                console.log(result.data);
                state.hostOrderLists = result.data;
            } else {
                $.hsf.stopLoading()
            }
        })
    },

    //管家端日历查询接口
    getCalendar({ state }, dateString) {
        let that = this;
        $.hsf.startLoading();
        let wxopenid = $.local_Storage.getItem('wxopenid');

        if (state.serveStatus == '0') {
            //wxopenid = '123456';
        }

        $.hsf.ajaxPost('wx/mgr/' + wxopenid + '/' + dateString + '/calendar', '', '', function(result) {
            console.log(result);
            if (result.code == '200') {
                $.hsf.stopLoading()

                state.calendarLists = result.data;
            } else {
                if (result.code == '4007' && state.serveStatus == '1') {
                    state.isGuanjia = false;
                }

                $.hsf.stopLoading()
            }
        })
    },

    //管家端订单状态操作接口
    orderStatusChange({ state }, requestString) {
        $.hsf.startLoading()
        let wxopenid = $.local_Storage.getItem('wxopenid');
        if (state.serveStatus == '0') {
            //wxopenid = '123456';
        }
        $.hsf.ajaxPost('wx/mgr/' + wxopenid + '/' + requestString, '', '', function(result) {
            console.log(result);
            if (result.code == '200') {
                $.hsf.stopLoading()
                alert('修改成功');
                state.orderChangeResult = true;
            } else {
                $.hsf.stopLoading()
                if (result.msg) {
                    alert(result.msg)
                } else {
                    alert('请重试');
                }
            }
        })
    },

    //远期房态查询
    searchForwardRoomsStatus({ state }, requestString) {
        if (!requestString) {
            requestString = 0
        }
        let wxopenid = $.local_Storage.getItem('wxopenid');
        if (state.serveStatus == '0') {
            //wxopenid = '123456';
            requestString = 0;
        }
        $.hsf.ajaxPost('wx/mgr/' + wxopenid + '/rooms/' + requestString + '/status', '', '', function(result) {
            console.log(result);
            $.hsf.startLoading()
            if (result.code == '200') {
                $.hsf.stopLoading();
                if (state.serveStatus == '0') {
                    state.forwardRoomsStatus = result.data;
                } else {
                    state.forwardRoomsStatus = state.forwardRoomsStatus.concat(result.data);
                }
                //state.forwardRoomsStatus = state.forwardRoomsStatus.concat(result.data);
            } else {
                $.hsf.stopLoading()
                if (result.msg) {
                    state.textError = result.msg;
                } else {
                    alert('请重试');
                }
            }
        })
    },

}